from xpcom import components


class ContentPolicyPython:
    _com_interfaces_ = components.interfaces.nsIContentSecurityPolicy
    _reg_clsid_ = "{648639fb-05a4-4695-a3a4-9cd9607951e6}"
    _reg_contractid_ = "@ucweb.com/pycontentpolicy;1"

    def __init__(self):
        pass

    def __del__(self):
        pass

    def shouldLoad(self, aContentType, aContentLocation, aRequestOrigin, aContext, aMimeTypeGuess, aExtra):
        #print '^^^^^^^^^^^^^^^^^^^^^^^shouldLoad^^^^^^^^^^^^^^^^^^^^^^^^^^^^'
        if 3 == aContentType:
            content = str(aContext)
            if content != '' and content.find('nsIDOMHTMLImageElement') != -1:
                return -2
            else:
                return 1
        else:
            return 1

    def shouldProcess(self, aContentType, aContentLocation, aRequestOrigin, aContext, aMimeType, aExtra):
        #print '^^^^^^^^^^^^^^^^^^^^^^^shouldProcess ^^^^^^^^^^^^^^^^^^^^^^^^^'
        return 1
